package fy.mdm.dao;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.soa.eis.adapter.framework.message.IMsgObject;
import com.soa.eis.adapter.framework.message.impl.MsgObject;

public class MaterialCodeMqReqXml {

	public static IMsgObject add(String ssid, String seid, String codes) throws Exception {

		/*
		 * <?xml version="1.0" encoding="UTF-8"?>
		 * 
		 * <Service> <Route> <ServiceResponse/> <SourceSysID>06001</SourceSysID>
		 * <SerialNO>2017062206001000007</SerialNO>
		 * <ServiceID>06001000000003</ServiceID>
		 * <ServiceTime>20170622081723</ServiceTime> </Route> <Data> <Control/>
		 * <Request> <BOID>MDM_MAT_PURCHASE_STATUS_B</BOID> <ROW p_type="G"
		 * loop_num="1"> <MATERIEL_CODE>BGC0042G</MATERIEL_CODE>
		 * <MATERIEL_NAME>防弹材料</MATERIEL_NAME>
		 * <PURCHASE_STATUS>多选</PURCHASE_STATUS> <SUBSIDIARY>FYWD</SUBSIDIARY>
		 * <EVALUATE_MAN>cc</EVALUATE_MAN>
		 * <EVALUATE_TIME>1987-07-11</EVALUATE_TIME>
		 * <ENABLE_STATUS>Ebable</ENABLE_STATUS> </ROW> </Request> <Response/>
		 * </Data> </Service>
		 */

		// List<GroupRecord> grs1 = new ArrayList<GroupRecord>();
		// 定义请求报文对象
		IMsgObject reqMo = new MsgObject(IMsgObject.MOType.initSR);
		String SourceSysID = ssid; // 请求方(发布方)
		String ServiceID = seid;// 响应方(发布方)
		// 获取系统时间
		Date date = new Date();
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMddHHmmss");
		String format = simpleDateFormat.format(date);
		// 对请求报文对象进行设置
		reqMo.setSourceSysID(SourceSysID); // 设置报文 请求方系统号
		reqMo.setSerialNO(
				format.substring(0, 8) + SourceSysID + String.format("%06d", ++MaterialRequestNoTimerTask.requestNo));// 设置报文流水号,第三段表示今天发送的第几的一次报文
		reqMo.setServiceID(ServiceID); // 设置报文 提供方服务号
		reqMo.setServiceDateTime(format); // 设置报文 日期时间
		// reqMo.setReqValue("BOID","mdm_materiel_b_f");

		reqMo.setReqValue("MATERIEL_CODE", codes);
//		if(model!=null){
//			reqMo.setReqValue("EXTEND_C", model);
//		}if(brand!=null){
//			reqMo.setReqValue("FONE_DISCRIBE_W", brand);
//		}
		/*
		 * GroupRecord gr1 = new GroupRecord(); gr1.setName("ROW");
		 * gr1.setFieldValue("MATERIEL_CODE", codes); grs1.add(gr1);
		 * reqMo.setReqGroupRecord(grs1);
		 */
		return reqMo;

	}

	public static String AddZero(String str, int i) {
		while (str.length() < i)
			str = "0" + str;
		return str;
	}

}
